{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "254e9c0b-8358-42c8-980c-61654b0b9c33",
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl\n",
    "from perspective.widget import PerspectiveWidget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7a6965f9-0dc9-4759-b22c-6931caa4d3ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = pl.read_parquet(\"new_share.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8bbbdc3f-25c9-4bd6-a2ba-f6dfb39541d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2 = pl.read_parquet(\"stock_basic.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6f1351df-7cea-4913-8361-00966bb01e27",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "polars.dataframe.frame.DataFrame"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "df99eb99-a508-4e73-b5f1-ef57dcb95a48",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "d1 = d1.with_columns(\n",
    "    ipo_date=pl.col.ipo_date.str.to_date(\"%Y%m%d\"),\n",
    "    issue_date=pl.col.issue_date.str.to_date(\"%Y%m%d\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e8850982-ba05-4f28-ad23-bef4b6a67232",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (2_000, 12)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>ts_code</th><th>sub_code</th><th>name</th><th>ipo_date</th><th>issue_date</th><th>amount</th><th>market_amount</th><th>price</th><th>pe</th><th>limit_amount</th><th>funds</th><th>ballot</th></tr><tr><td>str</td><td>str</td><td>str</td><td>date</td><td>date</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;001390.SZ&quot;</td><td>&quot;001390&quot;</td><td>&quot;古麒绒材&quot;</td><td>2025-05-19</td><td>null</td><td>5000.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>2.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;603014.SH&quot;</td><td>&quot;732014&quot;</td><td>&quot;威高血净&quot;</td><td>2025-05-08</td><td>null</td><td>4114.0</td><td>2685.0</td><td>26.5</td><td>24.82</td><td>1.1</td><td>10.902</td><td>0.03</td></tr><tr><td>&quot;301595.SZ&quot;</td><td>&quot;301595&quot;</td><td>&quot;太力科技&quot;</td><td>2025-05-08</td><td>null</td><td>2707.0</td><td>1178.0</td><td>17.05</td><td>21.55</td><td>0.65</td><td>4.615</td><td>0.02</td></tr><tr><td>&quot;688755.SH&quot;</td><td>&quot;787755&quot;</td><td>&quot;汉邦科技&quot;</td><td>2025-05-07</td><td>null</td><td>2200.0</td><td>704.0</td><td>22.77</td><td>26.35</td><td>0.5</td><td>5.009</td><td>0.03</td></tr><tr><td>&quot;301636.SZ&quot;</td><td>&quot;301636&quot;</td><td>&quot;泽润新能&quot;</td><td>2025-04-28</td><td>null</td><td>1597.0</td><td>774.0</td><td>33.06</td><td>17.57</td><td>0.45</td><td>5.279</td><td>0.02</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;300776.SZ&quot;</td><td>&quot;300776&quot;</td><td>&quot;帝尔激光&quot;</td><td>2019-05-07</td><td>2019-05-17</td><td>1654.0</td><td>1654.0</td><td>57.71</td><td>22.99</td><td>1.6</td><td>9.543</td><td>0.01</td></tr><tr><td>&quot;300777.SZ&quot;</td><td>&quot;300777&quot;</td><td>&quot;中简科技&quot;</td><td>2019-05-06</td><td>2019-05-16</td><td>4001.0</td><td>3601.0</td><td>6.06</td><td>22.98</td><td>1.1</td><td>2.425</td><td>0.04</td></tr><tr><td>&quot;603267.SH&quot;</td><td>&quot;732267&quot;</td><td>&quot;鸿远电子&quot;</td><td>2019-04-30</td><td>2019-05-15</td><td>4134.0</td><td>3721.0</td><td>20.24</td><td>16.5</td><td>1.6</td><td>8.367</td><td>0.03</td></tr><tr><td>&quot;600989.SH&quot;</td><td>&quot;730989&quot;</td><td>&quot;宝丰能源&quot;</td><td>2019-04-30</td><td>2019-05-16</td><td>73336.0</td><td>66002.0</td><td>11.12</td><td>22.07</td><td>22.0</td><td>81.55</td><td>0.25</td></tr><tr><td>&quot;300778.SZ&quot;</td><td>&quot;300778&quot;</td><td>&quot;新城市&quot;</td><td>2019-04-25</td><td>2019-05-10</td><td>2000.0</td><td>2000.0</td><td>27.33</td><td>22.99</td><td>2.0</td><td>5.466</td><td>0.02</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (2_000, 12)\n",
       "┌───────────┬──────────┬──────────┬────────────┬───┬───────┬──────────────┬────────┬────────┐\n",
       "│ ts_code   ┆ sub_code ┆ name     ┆ ipo_date   ┆ … ┆ pe    ┆ limit_amount ┆ funds  ┆ ballot │\n",
       "│ ---       ┆ ---      ┆ ---      ┆ ---        ┆   ┆ ---   ┆ ---          ┆ ---    ┆ ---    │\n",
       "│ str       ┆ str      ┆ str      ┆ date       ┆   ┆ f64   ┆ f64          ┆ f64    ┆ f64    │\n",
       "╞═══════════╪══════════╪══════════╪════════════╪═══╪═══════╪══════════════╪════════╪════════╡\n",
       "│ 001390.SZ ┆ 001390   ┆ 古麒绒材 ┆ 2025-05-19 ┆ … ┆ 0.0   ┆ 2.0          ┆ 0.0    ┆ 0.0    │\n",
       "│ 603014.SH ┆ 732014   ┆ 威高血净 ┆ 2025-05-08 ┆ … ┆ 24.82 ┆ 1.1          ┆ 10.902 ┆ 0.03   │\n",
       "│ 301595.SZ ┆ 301595   ┆ 太力科技 ┆ 2025-05-08 ┆ … ┆ 21.55 ┆ 0.65         ┆ 4.615  ┆ 0.02   │\n",
       "│ 688755.SH ┆ 787755   ┆ 汉邦科技 ┆ 2025-05-07 ┆ … ┆ 26.35 ┆ 0.5          ┆ 5.009  ┆ 0.03   │\n",
       "│ 301636.SZ ┆ 301636   ┆ 泽润新能 ┆ 2025-04-28 ┆ … ┆ 17.57 ┆ 0.45         ┆ 5.279  ┆ 0.02   │\n",
       "│ …         ┆ …        ┆ …        ┆ …          ┆ … ┆ …     ┆ …            ┆ …      ┆ …      │\n",
       "│ 300776.SZ ┆ 300776   ┆ 帝尔激光 ┆ 2019-05-07 ┆ … ┆ 22.99 ┆ 1.6          ┆ 9.543  ┆ 0.01   │\n",
       "│ 300777.SZ ┆ 300777   ┆ 中简科技 ┆ 2019-05-06 ┆ … ┆ 22.98 ┆ 1.1          ┆ 2.425  ┆ 0.04   │\n",
       "│ 603267.SH ┆ 732267   ┆ 鸿远电子 ┆ 2019-04-30 ┆ … ┆ 16.5  ┆ 1.6          ┆ 8.367  ┆ 0.03   │\n",
       "│ 600989.SH ┆ 730989   ┆ 宝丰能源 ┆ 2019-04-30 ┆ … ┆ 22.07 ┆ 22.0         ┆ 81.55  ┆ 0.25   │\n",
       "│ 300778.SZ ┆ 300778   ┆ 新城市   ┆ 2019-04-25 ┆ … ┆ 22.99 ┆ 2.0          ┆ 5.466  ┆ 0.02   │\n",
       "└───────────┴──────────┴──────────┴────────────┴───┴───────┴──────────────┴────────┴────────┘"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "33698795-b00b-4514-a614-b2e248db19ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2=d2.with_columns(\n",
    "    list_date=pl.col.list_date.str.to_date(\"%Y%m%d\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5915e588-4442-4895-a73a-993dc57548ec",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Unknown input type TypeId(0x9239c1dd2628c7542bd7e58e9837955f)",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mValueError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[17]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mPerspectiveWidget\u001b[49m\u001b[43m(\u001b[49m\u001b[43md1\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/opt/anaconda3/envs/week07/lib/python3.12/site-packages/perspective/widget/widget.py:156\u001b[39m, in \u001b[36mPerspectiveWidget.__init__\u001b[39m\u001b[34m(self, data, index, limit, binding_mode, **kwargs)\u001b[39m\n\u001b[32m    153\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m limit \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m    154\u001b[39m     \u001b[38;5;28mself\u001b[39m._options.update({\u001b[33m\"\u001b[39m\u001b[33mlimit\u001b[39m\u001b[33m\"\u001b[39m: limit})\n\u001b[32m--> \u001b[39m\u001b[32m156\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_options\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/opt/anaconda3/envs/week07/lib/python3.12/site-packages/perspective/widget/widget.py:161\u001b[39m, in \u001b[36mPerspectiveWidget.load\u001b[39m\u001b[34m(self, data, **options)\u001b[39m\n\u001b[32m    159\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"Load the widget with data.\"\"\"\u001b[39;00m\n\u001b[32m    160\u001b[39m \u001b[38;5;66;03m# Viewer will ignore **options if `data` is a Table or View.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m161\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mPerspectiveWidget\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43moptions\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/opt/anaconda3/envs/week07/lib/python3.12/site-packages/perspective/viewer/viewer.py:210\u001b[39m, in \u001b[36mPerspectiveViewer.load\u001b[39m\u001b[34m(self, data, **options)\u001b[39m\n\u001b[32m    208\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m    209\u001b[39m     client = perspective.Server().new_local_client()\n\u001b[32m--> \u001b[39m\u001b[32m210\u001b[39m     \u001b[38;5;28mself\u001b[39m._table = \u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtable\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m=\u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43moptions\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    211\u001b[39m     \u001b[38;5;28mself\u001b[39m._client = client\n\u001b[32m    213\u001b[39m \u001b[38;5;66;03m# If the user does not set columns to show, synchronize viewer state\u001b[39;00m\n\u001b[32m    214\u001b[39m \u001b[38;5;66;03m# with dataset.\u001b[39;00m\n",
      "\u001b[31mValueError\u001b[39m: Unknown input type TypeId(0x9239c1dd2628c7542bd7e58e9837955f)"
     ]
    }
   ],
   "source": [
    "PerspectiveWidget(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4abd1ff9-7eb2-43e0-9799-dcbe75c972f0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9068486e-a529-4e5c-8070-69bae8be3682",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8246056-9304-4d02-ac38-baa604ca779a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
